<?php

namespace App\Service\Message;

use App\Model\UserAutoMsg;
use App\Model\UserProfile;
use App\Service\BaseService;

/**
 * 自动聊天消息设置提交
 */
class AutoMsgSubmitService extends BaseService
{
    public function handle()
    {
        $userId = $this->getUserId();
        $msgText = $this->request->input('auto_msg_text', '');
        $msgVoice = $this->request->input('auto_msg_voice', '');
        $duration = $this->request->input('duration', 0);
        $ret['result'] = UserProfile::updateAutoMsg($userId, $msgText, $msgVoice, $duration);
        //同时更新新版本
        UserAutoMsg::clearVoiceAndText($userId);
        UserAutoMsg::addRecord($userId, 'text', $msgText);
        UserAutoMsg::addRecord($userId, 'voice', $msgVoice, $duration);
        return $ret;
    }
}
